package com.xh.config.filter;

import com.xh.utils.ParamsUtil;
import com.xh.utils.RequestUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author wen
 * @apiNote 拦截所有请求
 * @since 2022/11/28
 */
@Slf4j
public class RequestFilter extends OncePerRequestFilter {

    @Override
    protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
        String ip = RequestUtil.getIpAddress(request);
        log.info("request filter...ip：{}, uri：{}, params：{}", ip, request.getRequestURI(), ParamsUtil.getParams(request));
        filterChain.doFilter(request, response);
    }

}
